import {NgModule, LOCALE_ID, APP_INITIALIZER, Injector, InjectionToken} from '@angular/core';
import {HttpClient, HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

import {DelonModule} from './delon.module';
import {CoreModule} from './core/core.module';
import {SharedModule} from './shared/shared.module';
import {AppComponent} from './app.component';
import {RoutesModule} from './routes/routes.module';
import {LayoutModule} from './layout/layout.module';
import {StartupService} from '@core/startup/startup.service';
import {DefaultInterceptor} from '@core/net/default.interceptor';
import {SimpleInterceptor} from '@delon/auth';
// angular i18n
import {registerLocaleData} from '@angular/common';
import localeZhHans from '@angular/common/locales/zh-Hans';

import {UEditorComponent, UEditorModule} from 'ngx-ueditor';
registerLocaleData(localeZhHans);

// JSON-Schema form
import {JsonSchemaModule} from '@shared/json-schema/json-schema.module';
import {FormsModule} from '@angular/forms';

export function StartupServiceFactory(startupService: StartupService): Function {
    return () => startupService.load();
}

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        HttpClientModule,
        DelonModule.forRoot(),
        CoreModule,
        SharedModule,
        LayoutModule,
        JsonSchemaModule,
        RoutesModule,
        FormsModule,

    ],
    providers: [
        {provide: LOCALE_ID, useValue: 'zh-Hans'},
        {provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true},
        {provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true},
        StartupService,
        {
            provide: APP_INITIALIZER,
            useFactory: StartupServiceFactory,
            deps: [StartupService],
            multi: true
        }
    ],
    bootstrap: [AppComponent]
})

export class AppModule {
}
